package com.bjesc_b2c.app.appraiset.mvp.view.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.adapter.TrajectoryListAdapter;
import com.bjesc_b2c.app.appraiset.base.BaseFragment;
import com.orhanobut.logger.Logger;
import com.rxretrofit_build.model.RxBusBean;

import java.util.List;

import master_bean.CustomerDetailsBean;

/**
 * Created by yidong on 2017/5/25.
 * 客户轨迹
 */

public class CustomerTrajectoryFragment extends BaseFragment {
    RecyclerView recyclerView;
    private List<CustomerDetailsBean.FollowHistoryBean> data;
    private TrajectoryListAdapter adapter;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            data = (List<CustomerDetailsBean.FollowHistoryBean>)getArguments().getSerializable("FollowList");
            Logger.e(data.size()+"CustomerTrajectoryFragment");
            Logger.e(data.get(0).getContent());
        }
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        contentView = inflater.inflate(R.layout.fragment_trajectory, null);
        recyclerView = (RecyclerView) contentView.findViewById(R.id.rvTrace);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new TrajectoryListAdapter(getActivity(),R.layout.layout_item_trajectoy,data);
        recyclerView.setAdapter(adapter);
        return super.onCreateView(inflater, container, savedInstanceState);
    }
//    @Override
//    public void onHiddenChanged(boolean hidden) {
//        super.onHiddenChanged(hidden);
//        if (!hidden) {	//rootview是Fragment通过inflate进来的布局
//        data = (List<CustomerDetailsBean.FollowHistoryBean>)getArguments().getSerializable("FollowList");
//            adapter.refresh(data);
//            Logger.e(data.get(0).getContent());
//        }
//    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onResume() {
        super.onResume();
//        data = (List<CustomerDetailsBean.FollowHistoryBean>)getArguments().getSerializable("FollowList");
//        adapter.refresh(data);
    }

    @Override
    protected void doOnNext(RxBusBean rxBusBean) {
        super.doOnNext(rxBusBean);
            if (rxBusBean.getRequestMark().equals("trajectory")&& adapter!=null){
                data = (List<CustomerDetailsBean.FollowHistoryBean>) rxBusBean.getO();
                if (data !=null)
                adapter.refresh(data);
            }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
